package com.yuyaogc.lowcode.engine.loader;

import com.yuyaogc.lowcode.engine.context.Context;
import com.yuyaogc.lowcode.engine.loader.spi.Iloader;
import com.yuyaogc.lowcode.engine.plugin.activerecord.Db;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;

/**
 * 应用加载
 * Created by bzGhost on 20230322.
 */
public class SdkLoader extends Loader {

    public static Logger logger = LoggerFactory.getLogger(SdkLoader.class);
    ServiceLoader<Iloader> serviceLoader = ServiceLoader.load(Iloader.class);
    @Override
    public void setUp() {
        try (Context context = new Context(null, Db.getConfig())) {
            serviceLoader.forEach(iloader -> iloader.onStart(context));
        } catch (Exception e){
            e.printStackTrace();
        }
    }
    @Override
    public void shutdown() {
        try (Context context = new Context(null, Db.getConfig())) {
            serviceLoader.forEach(iloader -> iloader.onDestroy(context));
        } catch (Exception e){
            e.printStackTrace();
        }
    }

}
